邏輯:分辨大小月,當月例假有幾天,任職區間有幾天例假和休假(自己輸入),每日薪水多少(除以非假日)
extra holiday(自己總共休假天數-含例假)
//觸發按鈕取input和日期表格內的值,value轉型後變成number
function calculateSalary() {
const totalSalary = parseFloat(document.getElementById("totalSalary").value); //取薪水
const startDate = new Date(document.getElementById("startDate").value);
const endDate = new Date(document.getElementById("endDate").value);
//"2023-10-25T00:00:00.000Z"
const extraHoliday = parseInt(document.getElementById("extraHoliday").value); //取例假
//宣告獲取年分
const iYear = endDate.getFullYear(); //number型別
//宣告獲取月份
const iMonth = endDate.getMonth(); //number型別
//判斷一個月有幾天
const daysInMonth = 32 - new Date(iYear, iMonth, 32).getDate();
const dateBetween = endDate.getDate() - startDate.getDate(); //number型別
const trueSalary =
(totalSalary / (daysInMonth - 8)) * (dateBetween - extraHoliday);
document.getElementById(
"result"
).innerHTML = `Total Salary for the selected range: ${trueSalary.toFixed(2)}`;
}